-
Notifications
You must be signed in to change notification settings - Fork 430
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Override MessageEventTarget's events' this-parameter type #1882
base: main
Are you sure you want to change the base?
Conversation
Thanks for the PR! This section of the codebase is owned by @saschanaz - if they write a comment saying "LGTM" then it will be merged. |
Probably better to autodetect whether there's inheritance/mixin relationship and use |
But in case this is urgent I think this is fine too. |
I think that's theoretically a good idea. But .. how many inheritance/mixin relationships are there? Even though If we do this, would you recommend putting the HTMLElement exclusion in overridingtypes.jsonc or hard-coded in the generator? Edit: looks like there are around 120 mixins. |
However, when I add manual exclusions, there are only 3 of them: AbstractWorker, GlobalEventHandlers and WindowEventHandlers. I'll try to come up with a property for overridingTypes.jsonc. |
There are only 3 right now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably apply to interfaces inherited by others, but looks good
Unfortunately, this solution still makes Worker invariant and breaks on examples like partytown's tests: interface PartytownWorker {
// ...
}
interface TestWorker extends PartytownWorker {
messages: any[]
}
// but you can't use a TestWorker as a PartytownWorker
// because this: this is ultimately invariant
declar var tw: TestWorker
var ptw: PartytownWorker = tw @rbuckton suggested making MessageEventTarget generic so that Worker and the other extenders can specify a fixed interface MessageEventTarget<T> {
onmessage: ((this: T, ...
}
interface Worker extends MessageEventTarget<Worker> {
} This is a delimited form of |
microsoft/TypeScript#60987 is the PR I'm using to test this on TS. |
This adds the ability to override the
this
parameter of a type's event handlers, which I need for MessageEventTarget to avoid breaking code.Technically, I believe
this: this
is correct for all event handlers, but it's expensive to compile and confusing to understand so I'd prefer to use it only when needed.I don't know if this is the right way to do this in the generator code. Corrections welcome.